package com.example.provider.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: qilongxin
 * @date: 2021/11/9 11:42
 */
@Configuration
public class RabbitmqDirectConfig {

    /**
     * 定义队列，取名testDirectQueue
     */
    @Bean
    public Queue testDirectQueue() {
        return new Queue("testDirectQueue", true);
    }

    /**
     * 定义交换机，取名testDirectExchange
     */
    @Bean
    public DirectExchange testDirectExchange() {
        return new DirectExchange("testDirectExchange", true, false);
    }

    /**
     * 将队列和交换机绑定，并设置匹配键：testDirectRouting
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(testDirectQueue()).to(testDirectExchange()).with("testDirectRouting");
    }

    @Bean
    public DirectExchange lonelyDirectExchange() {
        return new DirectExchange("lonelyDirectExchange");
    }

}
